Page({
  data: {
    nickname: '',
    avatar: ''
  },
  goLogin() {
    wx.navigateTo({
      url: '/pages/login/index?redirectURL=pages/my/index',
    })
  },
  onLoad(){
    // this.getUserInfo()
  },
  onShow(){
    this.getUserInfo()
  },
  async getUserInfo(){
    const {data:userInfo} = await wx.http({url:'/userInfo'}) 
    this.setData({
      nickname: userInfo.nickName,
      avatar: userInfo.avatar
    })
  },
  logout(){
    // 删除全局
    getApp().global.token = null
    wx.removeStorageSync('token')
    // 跳转登录页
    wx.navigateTo({
      url: '/pages/login/index',
    })
  }
})
